def kol_del(i):
    d = 0
    for ch in range(1, int(i ** 0.5) + 1):
        if i % ch == 0:
            d += 1
            if i / ch != ch:
                d += 1
    return i, d


sl = {
    "zero": "0",
    "one": "1",
    "two": "2",
    "three": "3",
    "four": "4",
    "five": "5",
    "six": "6",
    "seven": "7",
    "eight": "8",
    "nine": "9",
}
n = input()
if len(n.split()) != 3 or not all([i in sl.keys() for i in n.split()]):
    print("Wrong input")
else:
    for i in sl.keys():
        n = n.replace(i, sl[i])
    ch = int(n.replace(" ", ""))
    if ch < 100:
        print("Wrong input")
    else:
        i = 0
        while True:
            if kol_del(ch - i)[0] <= 2:
                print(ch - i)
                break
            if kol_del(ch + i)[1] <= 2:
                print(ch + i)
                break
            i += 1